package com.neudu.yyzx_service.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neudu.yyzx_service.common.JSONReturn;
import com.neudu.yyzx_service.pojo.Nursecontent;
import com.neudu.yyzx_service.pojo.Nurselevelitem;
import com.neudu.yyzx_service.service.NurselevelitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class NurselevelitemController {
    @Autowired
    private NurselevelitemService nurselevelitemService;
    @Autowired
    private JSONReturn jsonReturn;

    @RequestMapping("get_all_nurselevelitems")
    public String getAll(@RequestBody PageInfo pageInfo){
        try {
            PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
            //可以根据数据库设置一个state字段值，匹配在住的客户查询
            List<Nurselevelitem> list = nurselevelitemService.getalllevelitem();
            System.out.println(list);
            PageInfo<Nurselevelitem> pageInfoReturn = new PageInfo<>(list);
            return jsonReturn.returnSuccess(pageInfoReturn);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }

    @RequestMapping("get_nurselevelitems_by")
    public String getByCondition(@RequestBody Nurselevelitem nurselevelitem){
        try {
            LambdaQueryWrapper<Nurselevelitem> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(!ObjectUtils.isEmpty(nurselevelitem.getId()), Nurselevelitem::getId, nurselevelitem.getId())
                    .eq(!ObjectUtils.isEmpty(nurselevelitem.getLevelName()), Nurselevelitem::getLevelName, nurselevelitem.getLevelName())
                    .eq(!ObjectUtils.isEmpty(nurselevelitem.getNursingName()), Nurselevelitem::getNursingName, nurselevelitem.getNursingName());
            List<Nurselevelitem> nurselevelitems = nurselevelitemService.list(queryWrapper);
            return jsonReturn.returnSuccess(nurselevelitems);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }


    @RequestMapping("add_one_nurselevelitem")
    public String addOne(@RequestBody Nurselevelitem nurselevelitem){
        try {
            nurselevelitemService.save(nurselevelitem);
            return jsonReturn.returnSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }

    @RequestMapping("getnurselevelitemby_id")
    public String getById(@RequestParam("nurselevelitemid") Integer nurselevelitemid){
        try {
            Nurselevelitem nurselevelitem = nurselevelitemService.getById(nurselevelitemid);
            return jsonReturn.returnSuccess(nurselevelitem);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }

    @RequestMapping("modifynurselevelitemby_id")
    public String modifyById(@RequestBody Nurselevelitem nurselevelitem){
        try {
            nurselevelitemService.updateById(nurselevelitem);
            return jsonReturn.returnSuccess(nurselevelitem);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }

    @RequestMapping("removenurselevelitem_by_id")
    public String removeByid(@RequestParam("nurselevelitemid") Integer nurselevelitemid){
        try {
            nurselevelitemService.removeById(nurselevelitemid);
            return jsonReturn.returnSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }

}
